#ifndef __SPRITE_H__
#define __SPRITE_H__

//#include "Ogre.h"
//#include "AnimationMixState.h"
#include "FrameworkDef.h"
#include <btBulletDynamicsCommon.h>



#define  SAVAGE 0x00000001
#define  PIG	0x00000002
#define  YUMI	0x00000003


class Scene;
class ThorSceneManager;
class Sprite{
public:

#define  STANDING			0x00000001
#define	 STRAIGHT_RUNING	0x00000002
#define  TURNING			0x00000004



//FX state related
#define	 FX_ENABLED			0x00000001
#define  FX_DISABLED		0x00000002

#define  FX_CREATED			0x00000001
#define  FX_IGNORED			0x00000002


	Sprite(Ogre::SceneManager *, Ogre::Camera * );
	~Sprite();

	Ogre::SceneManager * m_pSceneMgr;
	Ogre::Camera * m_pCamera;
	Ogre::SceneNode * m_pSceneNode;
	Ogre::SceneNode * m_pShadowNode;
	Ogre::Entity * m_pEntity;
	AnimationMixState *m_pAnimationMixState;
	std::map<int,Ogre::Entity*> mEquipmentMap;

	Ogre::String mNameId;
	Ogre::uint32 mType;

	Ogre::Node *m_pSpriteNode;

	Ogre::Vector3 mPosition;
	Ogre::Vector3 mCenterOffset;
	Ogre::Quaternion mOrientation;
	Ogre::Vector3 mScale;
	bool mVisable;

	std::queue<Ogre::Vector3> mDestinationList;
	Ogre::Vector3 mDestination; //triggered in click event, then followed by destination list
	Ogre::Vector3 mAngularDestination;

	Ogre::Real mLinearSpeed;
	Ogre::Radian mAngularSpeed;

	Ogre::uint32 mState;
	Ogre::uint32 mFXCreated;


	bool mNeedSynchronize;
	bool mVanishStateEnable;
	Ogre::Real mVanishTimeLeft;
	Ogre::Real mVanishTimePassed;
	
	void init(Ogre::String spriteName);
	void load(Ogre::String _mNameId);
	
	virtual void _preload();
	virtual void _postload();

	virtual void update(Ogre::Real timeSinceLast);
	virtual void eventClick(int _xx, int _yy);
	virtual void eventMouseMove(int _x, int _y, int _xRel, int _yRel, bool isButtonDown);
	virtual void eventMouseRelease(int _xx, int _yy);
	virtual void stateMouseDown(int _x, int _y, int _xRel, int _yRel, bool isButtonDown);

	void setPosition(Ogre::Vector3 _pos);
	void setCenterOffset(Ogre::Vector3 _o);
	void setOrientation(Ogre::Quaternion _quat);
	void setScale(Ogre::Vector3 _scale);
	void setVisable(bool);
	void setVanish(Ogre::Real time);
	void setNoTransparent();
	void setVanishDisabled();
	void _vanishProcess(Ogre::Real timeSinceLast);

	Ogre::Entity * getEntity();
	Ogre::Node* getSpriteNode();
	Ogre::Quaternion getOrientation();

	void _createShadow(bool maxSize);

	virtual void spriteMove(int _xx, int _yy);
	virtual void animationChanging(Ogre::Real timeSinceLast);
	virtual void updateForMoving(Ogre::Real timeSinceLast);

	static Ogre::Vector3 _getInteractPosition3D(Ogre::Camera* _camera, 
		Ogre::Vector2 screenCoordinates, 
		Ogre::Real y = 0);

	void attachSkeletonEquipment(Ogre::String name, int partID);

	///////////////////////////FX related
	
	Ogre::uint32 mStateFX;
	btRigidBody* m_pRigidBody;
	btDiscreteDynamicsWorld* m_pDynamicsWorld;
	btScalar m_mass;
	btCollisionShape* m_pShape;
	btTransform m_worldTrans;
	btDefaultMotionState *m_pMotionState;

	/*createFX->>>>setFXVolumn*/
	/*setFXEnabled->>>setNeedSynchronize*/
	
	void synchronizeFX();
	void createFX(btDiscreteDynamicsWorld*);
	void setWorld(btDiscreteDynamicsWorld*);

	void setFXDisabled();
	void setFXEnabled();
	void setNeedSynchronize(bool);

	void setEnableCollision(bool);

	virtual void setFXVolumn();//virtual function

protected:
	void _setPositionFX(Ogre::Vector3);
	
};








#endif